package com.example.el;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/demo1")
public class ServletDemo1  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 准备数据
        List<String> courseList = new ArrayList<String>();
        courseList.add("Java");
        courseList.add("Python");
        courseList.add("Linux");
        courseList.add("Hadoop");

        //2. 存储到request域中
        req.setAttribute("courseDatas",courseList);

        //3. 转发到 el-demo.jsp
        req.getRequestDispatcher("/el-demo.jsp").forward(req,resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
